
package com.feib.soeasy.action;

import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontBind;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.LocalizableMessage;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.validation.SimpleError;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import net.sourceforge.stripes.validation.ValidationErrors;

import com.feib.soeasy.model.ColumnDefinition;
import com.feib.soeasy.model.CommissionCodeTable;
import com.feib.soeasy.model.FormatDefinition;
import com.feib.soeasy.model.Group;
import com.feib.soeasy.pagination.PaginatedList;
import com.feib.soeasy.service.CommissionCodeTableService;
import com.feib.soeasy.service.FormatDefinitionService;
import com.feib.soeasy.service.GroupService;
import com.feib.soeasy.service.UploadFileService;
import com.feib.soeasy.util.UserUtil;


/**
 * @title (#)Soez9008ActionBean.java<br>
 * @description 帳單項目設定<br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2011/1/19 create by Jimmy Liu<br>
 */
public class Soez9008ActionBean extends BaseActionBean {

    private static final String DEFAULT_JSP = "/WEB-INF/views/soez9008/soez9008.jsp";
    
    private static final String AJAX_EDIT_COMMISSION_JSP = "/WEB-INF/views/soez9008/soez9008EditCommission.jsp";
    
    private static final String AJAX_QUERY_JSP = "/WEB-INF/views/soez9008/soez9008List.jsp";
    
    private static final String AJAX_EDIT_APP_GROUP_JSP = "/WEB-INF/views/soez9008/soez9008EditAppGroup.jsp";
    
    private static final String AJAX_EDIT_APP_GROUP_POST_JSP = "/WEB-INF/views/soez9008/soez9008EditAppGroupPost.jsp";
    /**
     * 業者代號查詢畫面formatDefinition
     */
    private static final String AJAX_QUERY_GROUP_JSP = "/WEB-INF/views/soez9008/groupPopUpList.jsp";
    private static final String AFTER_CONFIRM_JSP = "/WEB-INF/views/soez9008/afterConfirm.jsp";    
    
    private static final String AJAX_EDIT_JSP = "/WEB-INF/views/soez9008/soez9008Edit.jsp";


    private String confirmMessage;
    
    private Group editGroup;
    
    private static List<ColumnDefinition> defaultPayerColumnDefinitions;
    static
    {
        int pos = 0;
        defaultPayerColumnDefinitions = new ArrayList<ColumnDefinition>();
        ColumnDefinition cd = new ColumnDefinition();
        cd.setColumnName("payerNo");
        cd.setColumnTitle("繳款人編號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10));//length = 10  
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultPayerColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerName");
        cd.setColumnTitle("姓名");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10));//length = 10  
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("payerEmail");
        cd.setColumnTitle("E-MAIL");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 50));//length = 50 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("payerTelNo");
        cd.setColumnTitle("電話");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20));//length = 20 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("payerCellNo");
        cd.setColumnTitle("手機號碼");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10));//length = 10 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("levelGround");
        cd.setColumnTitle("坪數");
        cd.setColumnType("2");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 3));//length = 3 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("parkingCount");
        cd.setColumnTitle("車位數");
        cd.setColumnType("2");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 3));//length = 3 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("houseNo");
        cd.setColumnTitle("門牌號碼");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 50));//length = 50 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("payerAddress");
        cd.setColumnTitle("聯絡地址");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 50));//length = 50 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("payerMemo");
        cd.setColumnTitle("備註");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 50));//length = 50 
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.TRUE);
        cd.setCanModify(Boolean.TRUE);
        defaultPayerColumnDefinitions.add(cd);        
    }
    
    /**
     * 學校
     */
    private static List<ColumnDefinition> defaultColumnDefinitionsSchool;
    static
    {
        int pos = 0;
        defaultColumnDefinitionsSchool = new ArrayList<ColumnDefinition>();
        ColumnDefinition cd = new ColumnDefinition();
        cd.setColumnName("virtualAccount");
        cd.setColumnTitle("繳費帳號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 16));//length = 16  
        cd.setHeader(Boolean.TRUE);
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("totalAmount");
        cd.setColumnTitle("應繳合計");
        cd.setColumnType("2");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("totalLoanableAmount");
        cd.setColumnTitle("減免後金額");
        cd.setColumnType("2");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
               
        cd = new ColumnDefinition();
        cd.setColumnName("payDue");
        cd.setColumnTitle("繳費期限");
        cd.setColumnType("3");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 8)); //length = 8
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentName");
        cd.setColumnTitle("帳單名稱");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 30)); //length = 30
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        /*
        cd = new ColumnDefinition();
        cd.setColumnName("period");
        cd.setColumnTitle("期別");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        */
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerName");
        cd.setColumnTitle("繳款人姓名");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerId");
        cd.setColumnTitle("繳款人編號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerEmail");
        cd.setColumnTitle("繳款人E-Mail");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 50)); //length = 50
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerBirthday");
        cd.setColumnTitle("繳款人生日");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 8)); //length = 8
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerAddress");
        cd.setColumnTitle("繳款人住址");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 70)); //length = 70
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerTelNo");
        cd.setColumnTitle("繳款人電話");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerCellNo");
        cd.setColumnTitle("繳款人手機");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("studentId");
        cd.setColumnTitle("學號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 15)); //length = 15
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("academicYear");
        cd.setColumnTitle("學年度");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 6)); //length = 6
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("semester");
        cd.setColumnTitle("學期");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 6)); //length = 6
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("department");
        cd.setColumnTitle("科系所");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("grade");
        cd.setColumnTitle("年級");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("classNo");
        cd.setColumnTitle("班級/班別");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("seatNo");
        cd.setColumnTitle("座號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 3)); //length = 3
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentNote1");
        cd.setColumnTitle("注意事項");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 470)); //length = 470
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentNote2");
        cd.setColumnTitle("最新消息");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 300)); //length = 300
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentNote3");
        cd.setColumnTitle("備註");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 100)); //length = 100
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        
        
        // -- 明細
        cd = new ColumnDefinition();
        cd.setColumnName("itemName");
        cd.setColumnTitle("繳費項目");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("amount");
        cd.setColumnTitle("金額");
        cd.setColumnType("2");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("itemName");
        cd.setColumnTitle("繳費項目");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("amount");
        cd.setColumnTitle("金額");
        cd.setColumnType("2");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitionsSchool.add(cd);
    }
    
    
    private static List<ColumnDefinition> defaultColumnDefinitions;
    static
    {
        int pos = 0;
        defaultColumnDefinitions = new ArrayList<ColumnDefinition>();
        ColumnDefinition cd = new ColumnDefinition();
        cd.setColumnName("virtualAccount");
        cd.setColumnTitle("繳費帳號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 16));//length = 16
        cd.setHeader(Boolean.TRUE);
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("totalAmount");
        cd.setColumnTitle("應繳合計");
        cd.setColumnType("2");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
               
        cd = new ColumnDefinition();
        cd.setColumnName("payDue");
        cd.setColumnTitle("繳費期限");
        cd.setColumnType("3");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 8)); //length = 8
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentName");
        cd.setColumnTitle("帳單名稱");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 30)); //length = 30
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("period");
        cd.setColumnTitle("期別");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerName");
        cd.setColumnTitle("繳款人姓名");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerId");
        cd.setColumnTitle("繳款人編號");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerEmail");
        cd.setColumnTitle("繳款人E-Mail");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 50)); //length = 50
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerBirthday");
        cd.setColumnTitle("繳款人生日");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 8)); //length = 8
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerAddress");
        cd.setColumnTitle("繳款人住址");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 70)); //length = 70
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerTelNo");
        cd.setColumnTitle("繳款人電話");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("payerCellNo");
        cd.setColumnTitle("繳款人手機");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 10)); //length = 10
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentNote1");
        cd.setColumnTitle("注意事項");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 470)); //length = 470
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentNote2");
        cd.setColumnTitle("最新消息");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 300)); //length = 300
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("paymentNote3");
        cd.setColumnTitle("備註");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 100)); //length = 100
        cd.setDisplay(Boolean.FALSE);
        cd.setQuery(Boolean.FALSE);
        cd.setHeader(Boolean.TRUE);
        cd.setCanDelete(Boolean.FALSE);
        cd.setCanModify(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        
        // -- 明細
        cd = new ColumnDefinition();
        cd.setColumnName("itemName");
        cd.setColumnTitle("繳費項目");
        cd.setColumnType("1");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("amount");
        cd.setColumnTitle("金額");
        cd.setColumnType("2");
        cd.setRequired(Boolean.TRUE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);

        cd = new ColumnDefinition();
        cd.setColumnName("itemName");
        cd.setColumnTitle("繳費項目");
        cd.setColumnType("1");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 20)); //length = 20
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
        
        cd = new ColumnDefinition();
        cd.setColumnName("amount");
        cd.setColumnTitle("金額");
        cd.setColumnType("2");
        cd.setRequired(Boolean.FALSE);
        cd.setBeginIndex(pos+1);
        cd.setEndIndex((pos = pos + 7)); //length = 7
        cd.setHeader(Boolean.FALSE);
        defaultColumnDefinitions.add(cd);
    }
    
    /**
     *  查詢條件
     */
    @ValidateNestedProperties({
         @Validate(field="group.groupNo", required=true, on={"doQuery"})
         
    })
    private FormatDefinition qryFormatDefinition;

    /**
     * 查詢結果
     */
    private PaginatedList<FormatDefinition> queryResult;
    

    @ValidateNestedProperties({
         @Validate(field="formatDefinitionPk", required=true, on={"toEditComission", "doAjaxDelete"})
         
    })
    private FormatDefinition editFormatDefinition;
    
    /**
     * 帳單業者查詢條件
     */
    private Group qryGroup;
    
    private String queryGroupTrigger;

    /**
     * 帳單業者查詢結果
     */
    private PaginatedList<Group> queryGroupResult;
    
    /**
     * 列出所有手續費
     */
    private List<CommissionCodeTable> commissionCodeTables;
    
    /**
     * 選擇的手續費
     */
    private List<CommissionCodeTable> checkCommissionCodeTables;
    
    @SpringBean("formatDefinitionService")
    private FormatDefinitionService formatDefinitionService;
    
    @SpringBean("groupService")
    private GroupService groupService;

    @SpringBean("uploadFileService")
    private UploadFileService uploadFileService;

    @SpringBean("commissionCodeTableService")
    private CommissionCodeTableService commissionCodeTableService;
    

    @DontBind
    @DefaultHandler
    public Resolution doDefault()
    {
        logger.debug("Enter doDefault mehtod.");
        return new ForwardResolution(DEFAULT_JSP); 
    }
    
    /**
     * 查詢
     * @return
     */
    public Resolution doQuery()
    {
        logger.debug("Enter doQuery mehtod.");
        
        try {
            Group dbGroup = this.groupService.findByExactGroupNo(qryFormatDefinition.getGroup().getGroupNo());
            if (null != dbGroup)
            {
                qryFormatDefinition.setGroup(dbGroup);
                Group group = new Group();
                group.setGroupPk(dbGroup.getGroupPk());
                if (null == queryResult)
                {
                    queryResult = new PaginatedList<FormatDefinition>();
                    queryResult.setPageSize(100);
                }
                queryResult = formatDefinitionService.queryByGroup(group, queryResult);
            }
            else
            {
                // 查無資料
                queryResult = new PaginatedList<FormatDefinition>();
            }
            
            qryFormatDefinition.setGroup(dbGroup);
        }
        catch (Exception e) {
            logger.error("查詢失敗", e);
        }
        
        //改成顯示在其他頁
        return new ForwardResolution(AJAX_QUERY_JSP);
       
       // return new ForwardResolution(DEFAULT_JSP); 
    }

    /**
     * 儲存
     * @return
     */
    public Resolution doAjaxSave()
    {
        logger.debug("Enter doAjaxSave mehtod.");
        StringBuffer message = new StringBuffer();
        try {
            
            // 檢核檔案是否存在
            if (StringUtils.isNotEmpty(this.getEditFormatDefinition().getJrxmlPath()))
            {
                try {
                    File jrxmlFile = new File(this.getEditFormatDefinition().getJrxmlPath());
                    
                    if (!jrxmlFile.isFile())
                        message.append("[ ").append(this.getEditFormatDefinition().getJrxmlPath()).append(" ]不是一個檔案或檔案不存在");
                    else if (!jrxmlFile.exists())
                        message.append("[ ").append(this.getEditFormatDefinition().getJrxmlPath()).append(" ]不存在");
                    else if (! jrxmlFile.getName().endsWith(".jrxml"))
                        message.append("[").append(this.getEditFormatDefinition().getJrxmlPath()).append("]非報表格式檔");                    
                }
                catch (Exception e) {
                    message.append("[ ").append(this.getEditFormatDefinition().getJrxmlPath()).append(" ]無存取權限");
                }
            }
            
            // 檢查 客至化檢核 class 是否存在
            if (StringUtils.isNotEmpty(this.getEditFormatDefinition().getCustomValidateClass()))
            {
                try {
                    Class.forName(this.getEditFormatDefinition().getCustomValidateClass());                    
                }
                catch (Exception e) {
                    if (message.length() != 0)
                        message.append("<br /><br />");
                    
                    message.append("客製化檢核類別[").append(this.getEditFormatDefinition().getJrxmlPath()).append("]不存在");
                }
            }
            
            if (0 == message.length())
            {
                boolean isNew = null == this.getEditFormatDefinition().getFormatDefinitionPk();
                if (! isNew)
                {
                    FormatDefinition dbFormatDefinition  = this.formatDefinitionService.getFormatDefinitionByPk(this.getEditFormatDefinition().getFormatDefinitionPk());
                    dbFormatDefinition.setCustomPdfClass(this.getEditFormatDefinition().getCustomPdfClass());
                    dbFormatDefinition.setCustomValidateClass(this.getEditFormatDefinition().getCustomValidateClass());
                    if (null == this.getEditFormatDefinition().getDeleted())
                        dbFormatDefinition.setDeleted(Boolean.FALSE);
                    else
                        dbFormatDefinition.setDeleted(this.getEditFormatDefinition().getDeleted());
                    dbFormatDefinition.setFormatName(this.getEditFormatDefinition().getFormatName());
                    dbFormatDefinition.setJrxmlPath(this.getEditFormatDefinition().getJrxmlPath());
                    this.editFormatDefinition = dbFormatDefinition;
                }
                else
                {
                    Group group = null;
                    try{
                        group = this.groupService.findByExactGroupNo(this.getEditFormatDefinition().getGroup().getGroupNo());
                        
                        if (null == group)
                            throw new Exception("無此帳單業者代號:"+this.getEditFormatDefinition().getGroup().getGroupNo());
                    }
                    catch(Exception e)
                    {
                        logger.info("帳單業者代號查詢錯誤", e);
                        message.append("帳單業者代號錯誤!");
                        StreamingResolution resolution = new StreamingResolution("text/html;charset=utf-8", new StringReader(message.toString()));
                        resolution.setCharacterEncoding("UTF-8");
                        return resolution;
                    }
                    this.editFormatDefinition.setGroup(group);
                    if (null == this.getEditFormatDefinition().getDeleted())
                        this.editFormatDefinition.setDeleted(Boolean.FALSE);
                    if (null == this.getEditFormatDefinition().getFormatType())
                        this.editFormatDefinition.setFormatType(new Integer(1));
                    
                    this.editFormatDefinition.setBatchUsed(Boolean.FALSE); // 非自動產生繳款單使用
                    
                    List<ColumnDefinition> columnDefinitions = new ArrayList<ColumnDefinition>();
                    this.editFormatDefinition.setColumnDefinitions(columnDefinitions);
                    
                    List<ColumnDefinition> tempDefaultColumnDefinitions = defaultColumnDefinitions;
                    
                    if (this.editFormatDefinition.getGroup().getGroupType().equals(Group.GROUP_TYPE_SCHOOL))
                        tempDefaultColumnDefinitions = defaultColumnDefinitionsSchool;
                    
                    if (new Integer(2).equals(this.getEditFormatDefinition().getFormatType()))
                    {
                        // 改為繳款人default 設定欄位
                        tempDefaultColumnDefinitions = defaultPayerColumnDefinitions;
                    }
                    
                    for(ColumnDefinition cd : tempDefaultColumnDefinitions)
                    {
                        ColumnDefinition newCd = new ColumnDefinition();
                        newCd.setColumnName(cd.getColumnName());
                        newCd.setColumnTitle(cd.getColumnTitle());
                        newCd.setColumnType(cd.getColumnType());
                        newCd.setRequired(cd.getRequired());
                        newCd.setDisplay(cd.getDisplay());
                        newCd.setQuery(cd.getQuery());
                        newCd.setHeader(cd.getHeader());
                        newCd.setFormatDefinition(editFormatDefinition);
                        newCd.setBeginIndex(cd.getBeginIndex());
                        newCd.setEndIndex(cd.getEndIndex());
                        columnDefinitions.add(newCd);
                    }
                    
                    
                }
                
                if (isNew)
                {
	                // 設定特殊代碼 XXX
	                Set<CommissionCodeTable> commissionCodeTables = new HashSet<CommissionCodeTable>();
	                editFormatDefinition.setCommissionCodeTables(commissionCodeTables);
	                PaginatedList<CommissionCodeTable> codes = commissionCodeTableService.queryCommissionCodeTable("XXX", null);
	                if (null == codes || null == codes.getPaginatedList() || 0 == codes.getPaginatedList().size())
	                    throw new RuntimeException("請先設定特殊手續費代碼XXX");
	                CommissionCodeTable code = new CommissionCodeTable();
	                code.setCommissionCodePk(codes.getPaginatedList().get(0).getCommissionCodePk());
	                commissionCodeTables.add(code);
                }
                
                editFormatDefinition = this.formatDefinitionService.save(editFormatDefinition);
                
                message.append("儲存成功").append("<input type='hidden' id='doAjaxSaveResultCode' value='1'/>");
                
                if (isNew && new Integer(1).equals(this.getEditFormatDefinition().getFormatType())) // 新增 且是  繳費單資料
                {
                    message.append("<br/>請繼續設定手續費");
                    message.append("<input type='hidden' id='continueEditCommission' value='1'/>");
                    message.append("<input type='hidden' id='doAjaxSaveFormatDefinitionPk' value='").append(this.getEditFormatDefinition().getFormatDefinitionPk()).append("'/>");
                }
            }
            
            
        }
        catch (Exception e) {
            logger.error("帳單項目設定儲存失敗", e);
            message.append("儲存失敗");
        }
        StreamingResolution resolution = new StreamingResolution("text/html;charset=utf-8", new StringReader(message.toString()));
        resolution.setCharacterEncoding("UTF-8");
        return resolution;
    }

    /**
     * 刪除，只有未有轉入的設定可以刪除
     * @return
     */
    public Resolution doAjaxDelete()
    {
        logger.debug("Enter doAjaxDelete mehtod.");
        StringBuffer message = new StringBuffer();
        try {
            
            /* step1 檢核是否已有上傳紀錄 */
            int cnt = uploadFileService.countUploadFileByFormatDefinition(this.editFormatDefinition);
            
            if (cnt > 0)
            {
                message.append("已有檔案上傳紀錄，無法刪除！");
            }
            else
            {
                /* setp2 如果沒有才可以刪除 */
                this.formatDefinitionService.delete(this.editFormatDefinition);
                message.append("刪除成功").append("<input type='hidden' id='doAjaxDeleteResultCode' value='1'/>");
            }
            
        }
        catch (Exception e) {
            logger.error("帳單項目設定刪除失敗", e);
            message.append("刪除失敗");
        }

        StreamingResolution resolution = new StreamingResolution("text/html;charset=utf-8", new StringReader(message.toString()));
        resolution.setCharacterEncoding("UTF-8");
        return resolution;       
    }
    
    /**
     * 手續費設定查詢
     * @return
     */
    public Resolution toEditComission()
    {
        logger.debug("Enter toEditComission mehtod.");
        try {
            
            FormatDefinition dbFormatDefinition  = this.formatDefinitionService.getFormatDefinitionByPk(this.getEditFormatDefinition().getFormatDefinitionPk());
            
            Set<CommissionCodeTable> dbCommisions = dbFormatDefinition.getCommissionCodeTables();
            
            this.commissionCodeTables = this.commissionCodeTableService.queryAll();
            
            for(CommissionCodeTable code : this.commissionCodeTables)
            {
                for(CommissionCodeTable dbCode: dbCommisions)
                {
                    if (code.equals(dbCode))
                    {
                        code.setChecked(Boolean.TRUE);
                        //dbCommisions.remove(dbCode);
                        break;
                    }
                }
            }
            
            this.editFormatDefinition = dbFormatDefinition;
            
        }
        catch (Exception e) {
            logger.error("手續費設定查詢失敗", e);
        }

        return new ForwardResolution(AJAX_EDIT_COMMISSION_JSP); 
    }
    
    /**
     * 儲存手續費設定
     * @return
     */
    public Resolution doAjaxSaveComission()
    {
        logger.debug("Enter doAjaxSaveComission mehtod.");
        StringBuffer message = new StringBuffer();
        try {
            
            FormatDefinition dbFormatDefinition  = this.formatDefinitionService.getFormatDefinitionByPk(this.getEditFormatDefinition().getFormatDefinitionPk());
            
            Set<CommissionCodeTable> newCommisions = new HashSet<CommissionCodeTable>();
            
                        
            if (null != checkCommissionCodeTables)
            {
                for(CommissionCodeTable code : checkCommissionCodeTables)
                {
                    if (null != code)
                        newCommisions.add(code);
                }
            }            
            
            dbFormatDefinition.setCommissionCodeTables(newCommisions);
            
            this.editFormatDefinition = this.formatDefinitionService.save(dbFormatDefinition);
            
            message.append("儲存成功").append("<input type='hidden' id='doAjaxSaveComissionResultCode' value='1'/>");
            
        }
        catch (Exception e) {
            logger.error("儲存手續費設定失敗", e);
            message.append("儲存失敗");
        }

        StreamingResolution resolution = new StreamingResolution("text/html;charset=utf-8", new StringReader(message.toString()));
        resolution.setCharacterEncoding("UTF-8");
        return resolution;
    }
    
    public Resolution toEditAppGroup()
    {
        logger.debug("Enter toEditAppGroup mehtod.");
        try {
        	//formatDefinitionService
            editGroup = groupService.findByExactGroupNo(editFormatDefinition.getGroup().getGroupNo());
        }
        catch (Exception e) {
            logger.error("帳務處理費設定查詢失敗", e);
        }

        return new ForwardResolution(AJAX_EDIT_APP_GROUP_JSP); 
    }
    
    public Resolution toSaveAppGroup()
    {
        logger.debug("Enter toSaveAppGroup mehtod.");
        try {
        	if (editGroup.getPostAmount() != null){
        		/* 儲存帳務處理費 */
        	    groupService.updateAmount(editGroup);
        	} 
        	if (editGroup.getPostLevel1() != null){  
        		/* 郵局代收手續費 */
        	    groupService.updateLevel(editGroup);
        	}   
        	confirmMessage = "更新成功";
        }
        catch (Exception e) {
        	confirmMessage = "處理失敗！";
            logger.error("帳務處理費或郵局代收手續費存檔失敗", e);
        }

        return new ForwardResolution(AFTER_CONFIRM_JSP);
    }
    
    public Resolution toEditAppGroupPost()
    {
        logger.debug("Enter toEditAppGroupPost mehtod.");
        try {
        	//formatDefinitionService
            editGroup = groupService.findByExactGroupNo(editFormatDefinition.getGroup().getGroupNo());
        }
        catch (Exception e) {
            logger.error("郵局代收手續費設定查詢失敗", e);
        }

        return new ForwardResolution(AJAX_EDIT_APP_GROUP_POST_JSP); 
    }
    
    /**
     * 帳單業者查詢
     * @return
     */
    public Resolution doAjaxQueryGroups()
    {
        logger.debug("Enter doAjaxQueryGroups mehtod.");
        try {
            //如果不是銀行端，則查詢條件要加入帳單業者限制
            if (!UserUtil.isBankGroup())
            {
                throw new Exception(new LocalizableMessage("no.authority").getMessage(getContext().getLocale()));
            }


            //USER未輸入查詢條件，所以查詢物件會是NULL(查詢物件不可為NULL)
            if (null == qryGroup)
                qryGroup = new Group();

            //呼叫服務查詢
            queryGroupResult = groupService.queryByGroupExcludeBank(qryGroup, queryGroupResult);
        }
        catch (Exception e) {
            logger.error("帳單項目設定-帳單業者查詢錯誤(Soez9008ActionBean.doAjaxQueryGroups):", e);

            // 轉換錯誤訊息
            ValidationErrors errors = new ValidationErrors();
            errors.addGlobalError(new SimpleError("查詢錯誤！"));
            getContext().setValidationErrors(errors);
            // 回傳 錯誤 HTML fragments
            return super.errorsToHtmlStreams(errors);
        }

        return new ForwardResolution(AJAX_QUERY_GROUP_JSP);
    }

    
    public Resolution toAjaxEditFomatDefinition()
    {
        this.editFormatDefinition = this.formatDefinitionService.queryByPk( this.editFormatDefinition.getFormatDefinitionPk());
        return new ForwardResolution(AJAX_EDIT_JSP); 
    }
    
    
    public Resolution toNewAjaxEditFomatDefinition()
    {
        logger.debug("Enter AjaxEditFomatDefinition mehtod.");
        this.editFormatDefinition = new FormatDefinition();        
        
        return new ForwardResolution(AJAX_EDIT_JSP); 
    }
    
    
    
    /**
     * @return the qryFormatDefinition
     */
    public FormatDefinition getQryFormatDefinition() {
        return qryFormatDefinition;
    }

    
    /**
     * @param qryFormatDefinition the qryFormatDefinition to set
     */
    public void setQryFormatDefinition(FormatDefinition qryFormatDefinition) {
        this.qryFormatDefinition = qryFormatDefinition;
    }

    
    /**
     * @return the queryResult
     */
    public PaginatedList<FormatDefinition> getQueryResult() {
        return queryResult;
    }

    
    /**
     * @param queryResult the queryResult to set
     */
    public void setQueryResult(PaginatedList<FormatDefinition> queryResult) {
        this.queryResult = queryResult;
    }

    
    /**
     * @return the qryGroup
     */
    public Group getQryGroup() {
        return qryGroup;
    }

    
    /**
     * @param qryGroup the qryGroup to set
     */
    public void setQryGroup(Group qryGroup) {
        this.qryGroup = qryGroup;
    }

    
    /**
     * @return the queryGroupResult
     */
    public PaginatedList<Group> getQueryGroupResult() {
        return queryGroupResult;
    }

    
    /**
     * @param queryGroupResult the queryGroupResult to set
     */
    public void setQueryGroupResult(PaginatedList<Group> queryGroupResult) {
        this.queryGroupResult = queryGroupResult;
    }

    
    /**
     * @return the editFormatDefinition
     */
    public FormatDefinition getEditFormatDefinition() {
        return editFormatDefinition;
    }

    
    /**
     * @param editFormatDefinition the editFormatDefinition to set
     */
    public void setEditFormatDefinition(FormatDefinition editFormatDefinition) {
        this.editFormatDefinition = editFormatDefinition;
    }

    
    /**
     * @return the commissionCodeTables
     */
    public List<CommissionCodeTable> getCommissionCodeTables() {
        return commissionCodeTables;
    }

    
    /**
     * @param commissionCodeTables the commissionCodeTables to set
     */
    public void setCommissionCodeTables(List<CommissionCodeTable> commissionCodeTables) {
        this.commissionCodeTables = commissionCodeTables;
    }

    
    /**
     * @return the checkCommissionCodeTables
     */
    public List<CommissionCodeTable> getCheckCommissionCodeTables() {
        return checkCommissionCodeTables;
    }

    
    /**
     * @param checkCommissionCodeTables the checkCommissionCodeTables to set
     */
    public void setCheckCommissionCodeTables(List<CommissionCodeTable> checkCommissionCodeTables) {
        this.checkCommissionCodeTables = checkCommissionCodeTables;
    }

    
    /**
     * @return the queryGroupTrigger
     */
    public String getQueryGroupTrigger() {
        return queryGroupTrigger;
    }

    
    /**
     * @param queryGroupTrigger the queryGroupTrigger to set
     */
    public void setQueryGroupTrigger(String queryGroupTrigger) {
        this.queryGroupTrigger = queryGroupTrigger;
    }

	public Group getEditGroup() {
		return editGroup;
	}

	public void setEditGroup(Group editGroup) {
		this.editGroup = editGroup;
	}

	public String getConfirmMessage() {
		return confirmMessage;
	}

	public void setConfirmMessage(String confirmMessage) {
		this.confirmMessage = confirmMessage;
	}

}
